package crmdna.gspreadsheet;

import java.util.List;
import java.util.Map;

import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.Nullable;

import crmdna.common.APIResponse;
import crmdna.common.APIResponse.Status;

@Api(name = "spreadsheet")
public class GSpreadSheetApi {

	public APIResponse getPublishedSpreadsheetContents(
			@Named("spreadSheetKey") String gsKey,
			@Nullable @Named("maxLinesDefault2500") Integer maxLines, 
			@Nullable @Named("showStackTraceIfErrorDefaultFalse") Boolean showStackTrace,
			HttpServletRequest req) {

		try {
			if (maxLines == null)
				maxLines = 2500;

			List<Map<String, String>> listOfMap = GSpreadSheet
					.getPublishedSpreasheetAsListOfMap(gsKey, maxLines);

			return new APIResponse(Status.SUCCESS, listOfMap);

		} catch (Exception ex) {
			return new APIResponse(ex, showStackTrace, "Dummy Client", req, null);
		}
	}
}
